﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Gauss.Isp.Attributes
{
    /// <summary>
    /// This is an extension of the DescriptionAttribute class, supporting
    /// localized description strings.
    /// </summary>
    public sealed class LocalizedDescriptionAttribute : DescriptionAttribute
    {
        /// <summary>
        /// This is the current resource manager which is used to convert the
        /// display resource ID to the localized version.
        /// </summary>
        private static global::System.Resources.ResourceManager _resourceManager;

        /// <summary>
        /// This is the localized string that represents the given description
        /// Id.
        /// </summary>
        private string _localizedDescriptionString;

        /// <summary>
        /// This returns the resource manager used to get the localized string,
        /// and it caches the value in _resourceManager.
        /// </summary>
        internal static global::System.Resources.ResourceManager ResourceManager
        {
            get
            {
                if (_resourceManager == null)
                {
                    _resourceManager = new global::System.Resources.ResourceManager("Gauss.Isp.Resources", typeof(Resources).Assembly);
                }
                return _resourceManager;
            }
        }

        /// <summary>
        /// This creates a description by converting the descriptionId to the
        /// correct localized string.
        /// </summary>
        /// <param name="descriptionId">The resource ID of the description in the resources file.</param>
        public LocalizedDescriptionAttribute(string descriptionId)
            : base(descriptionId)
        {
            this._localizedDescriptionString = ResourceManager.GetString(descriptionId);
        }

        /// <summary>
        /// Returns the localized string for the given description ID.
        /// </summary>
        public override string Description
        {
            get
            {
                return _localizedDescriptionString;
            }
        }

    }
}
